from cgi import print_form
import math
from re import S


print(abs(-200))

a=abs
print(a(-1))

def nop():
    pass

def my_abs(x):
    if not isinstance(x,(int,float)):
        raise TypeError('bad openand type')
    if x>=0:
        return x
    else:
        return -x

print(my_abs(-100))

def move(x,y,step,angle=10):
    nx = x + step * math.cos(angle)
    ny = y - step * math.sin(angle)
    return nx, ny

x,y=move(100,100,60,math.pi/6)
print(x,y)

s=move(100,100,60,math.pi/6)
print(s)
print(s[0])

def add_end(L=[]):
    L.append('END')
    return L

print(add_end())
print(add_end())
print(add_end())

def add_end(L=None):
    if L==None:
        L=[]
    L.append('END')
    return L

print(add_end())
print(add_end())
print(add_end())

# 可变参数
def calc(*num):
    sum=0
    for n in num:
        sum+=n*n
    return sum

print(calc())    
print(calc(1,2,3,4))   

nums = [1, 2, 3]
print(calc(*nums))    

# 关键字参数
def person(name, age, **kw):
    print('name:', name, 'age:', age, 'other:', kw)

person('Michael', 30)
person('Bob', 35, city='Beijing')
person('Adam', 45, gender='M', job='Engineer')    

extra = {'city': 'Beijing', 'job': 'Engineer'}
person('Jack', 24, **extra)

# 命名关键字参数 强制指定可选参数
def person(name, age, *args, city, job):
    print(name, age, args, city, job)

person('Jack', 24, city='Beijing', job='Engineer')

def f1(a, b, c=0, *args, **kw):
    print('a =', a, 'b =', b, 'c =', c, 'args =', args, 'kw =', kw)

def f2(a, b, c=0, *, d, **kw):
    print('a =', a, 'b =', b, 'c =', c, 'd =', d, 'kw =', kw)

# >>> f1(1, 2)
# a = 1 b = 2 c = 0 args = () kw = {}
# >>> f1(1, 2, c=3)
# a = 1 b = 2 c = 3 args = () kw = {}
# >>> f1(1, 2, 3, 'a', 'b')
# a = 1 b = 2 c = 3 args = ('a', 'b') kw = {}
# >>> f1(1, 2, 3, 'a', 'b', x=99)
# a = 1 b = 2 c = 3 args = ('a', 'b') kw = {'x': 99}
# >>> f2(1, 2, d=99, ext=None)
# a = 1 b = 2 c = 0 d = 99 kw = {'ext': None}

# 可变参数既可以直接传入：func(1, 2, 3)，又可以先组装list或tuple，再通过*args传入：func(*(1, 2, 3))；
# 关键字参数既可以直接传入：func(a=1, b=2)，又可以先组装dict，再通过**kw传入：func(**{'a': 1, 'b': 2})。

# def move(n, a, b, c):
#     for x in a